{{template "base/base.html" .}}
{{define "head"}}
{{end}}
{{define "body"}}
<div class="testing">
<header class="main">
	<h1><strong>Retina</strong> Dashboard</h1>
	<input type="text" value="search" />
</header>
<section class="user">
	<div class="profile-img">
		<p><img src="images/uiface2.png" alt="" height="40" width="40" /> Welcome back John Doe</p>
	</div>
	<div class="buttons">
        <span class="button blue"><a href="/admin/login_out/{{.tel}}">登出</a></span>
	</div>
</section>
</div>
<nav>
	<ul>
		<li><a href="/admin/index/{{.tel}}"><span class="icon">&#128711;</span> 设备监控</a></li>
		<li><a href="/admin/admin_list/{{.tel}}"><span class="icon">&#128101;</span>管理员<span class="pip">3</span></a></li>
		<li>
			<a href="/admin/sys_setting/{{.tel}}"><span class="icon">&#9881;</span>系统设置</a>
		</li>
        <li class="section">
            <a href="/admin/show_remote_list/{{.tel}}"><span class="icon">&#9881;</span>显示遥控数据</a>
        </li>
        <li>
            <a href="/admin/add_remote_data/{{.tel}}"><span class="icon">&#9881;</span>添加遥控数据</a>
        </li>
	</ul>
</nav>

<section class="alert">
        <button id="del_btn" class="green">删除</button>
</section>
<section class="content">
	<section class="widget">
		<header>
			<span class="icon">&#128100;</span>
			<hgroup>
				<h1>Users</h1>
				<h2>Current member accounts</h2>
			</hgroup>
			<aside>
				<span>
					<a href="#">&#9881;</a>
					<ul class="settings-dd">
						<li><label>Option a</label><input type="checkbox" /></li>
						<li><label>Option b</label><input type="checkbox" checked="checked" /></li>
						<li><label>Option c</label><input type="checkbox" /></li>
					</ul>
				</span>
			</aside>
		</header>
		<div class="content">
			<table id="myTable" border="0" width="100">
				<thead>
					<tr>
                        <th>选中</th>
                        <!--<th>遥控器的ID</th>-->
						<th>遥控器名字</th>
						<th>编号</th>
						<th>版本号</th>

                        <th>详情</th>
					</tr>
				</thead>
					<tbody id="remote_list">

					</tbody>
				</table>
		</div>
	</section>
</section>
<script type="text/javascript">
$(function () {
    var tel = {{.tel}}
    $(document).ready(function() {
     $.getJSON('http://'+window.location.host+'/admin/api/get_remote_list/'+tel, function(data) {
			//alert(data.length)

        	$.each(data.Data,function(index,element){
				    $("#remote_list").append('<tr><td><input type="checkbox" name="checkbox" id="'+element.ObjectId+'"></td>'+'<td class="avatar">'+ element.RemoteName+'</td><td>'+element.No+'</td><td>'+element.Version+'</td><td>'+element.DeviceType+'</td><td><a href=/admin/update_remote/'+tel+'/'+element.ObjectId+'>详情</a></tr>')

			});
    	});

    });

});
</script>

<script type="text/javascript">
    $(document).ready(function() {
        $("#del_btn").click(function(){
        var objs = $(":input[type='checkbox'][name='checkbox']")
        var objs_id = new Array();
            var num = objs.length

            for(var i=0;i< num;i++){
                    if(objs[i].checked == true){
                        //console.log(objs[i].id)
                        objs_id.push(objs[i].id)
                 }
             }
            if (objs_id.length <= 0){
                alert("选中一个你要删除的数据");
                return false
            }
            var data = {'ObjectIDs':objs_id}
            console.log(data)
            $.post('http://'+window.location.host+'/admin/api/del_remotes/'+{{.tel}},JSON.stringify(data),function(data){
				            console.log(data)
		                    if(data.RespCode == 200){
					             alert(data.Msg);
					             window.location.reload();
				            }else if(data.RespCode == 8){
					             alert(data.Msg);
					             window.location.reload();
				            }

		            });
        });
});
</script>
{{end}}